/*
 * @Author: tcosfish
 * @Date: 2022-08-19 10:37:59
 * @LastEditors: tcosfish
 * @LastEditTime: 2022-08-19 16:42:04
 * @FilePath: \loadFile\src\database\views\Record.view.ts
 */

import { ViewColumn, ViewEntity } from "typeorm"

@ViewEntity({
  expression: `
  SELECT
    \`record\`.\`code\` AS \`code\`,
    \`record\`.\`name\` AS \`name\`,
    sum( \`record\`.\`debit\` ) AS \`sum_debit\`,
    sum( \`record\`.\`credit\` ) AS \`sum_credit\`,
    count( 0 ) AS \`number\` 
  FROM
    \`record\` 
  GROUP BY
    \`record\`.\`name\`
  `,
})
export class RecordView {
  @ViewColumn()
  code: string = ""

  @ViewColumn()
  name: string = ""

  @ViewColumn()
  sum_debit: string = ""

  @ViewColumn()
  sum_credit: string = ""
}
